package xyz.kongbai121.modules.numcount.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import xyz.kongbai121.common.validator.ValidatorUtils;
import xyz.kongbai121.common.validator.group.AddGroup;
import xyz.kongbai121.common.validator.group.UpdateGroup;

import io.swagger.annotations.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import xyz.kongbai121.modules.numcount.entity.WechatUserEntity;
import xyz.kongbai121.modules.numcount.service.WechatUserService;
import xyz.kongbai121.common.utils.PageUtils;
import xyz.kongbai121.common.utils.Result;



/**
 * 微信用户
 *
 * @author kongbai121
 * @date 2021-11-27 18:05:28
 */
@Api(tags = "微信用户")
@RestController
@RequestMapping("/numcount/wechatuser")
public class WechatUserController {
    @Autowired
    private WechatUserService wechatUserService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表")
    @GetMapping("/list")
    @RequiresPermissions("numcount:wechatuser:list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页码", paramType = "query", dataType = "long", required=true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", paramType = "query", dataType = "long", required=true),
    })
    public Result<PageUtils> list(@RequestParam(value = "curPage") Long curPage,
                                  @RequestParam(value = "pageSize") Long pageSize){

        Map<String, Object> params = new HashMap<>();
        params.put("page", curPage);
        params.put("limit", pageSize);
        PageUtils page = wechatUserService.queryPage(params);

        return Result.ok(page);
    }


    /**
     * 详情
     */
    @ApiOperation(value = "详情")
    @GetMapping("/info/{id}")
    @RequiresPermissions("numcount:wechatuser:info")
    public Result<WechatUserEntity> info(@ApiParam(value = "id", example = "0", required=true) @PathVariable("id") Long id){
		WechatUserEntity wechatUser = wechatUserService.getById(id);

        return Result.ok(wechatUser);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存")
    @PostMapping("/save")
    @RequiresPermissions("numcount:wechatuser:save")
    public Result save(@ApiParam(value = "实体", required=true) @RequestBody WechatUserEntity wechatUser){
        ValidatorUtils.validateEntity(wechatUser, AddGroup.class);

		wechatUserService.save(wechatUser);

        return Result.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @PutMapping("/update")
    @RequiresPermissions("numcount:wechatuser:update")
    public Result update(@ApiParam(value = "实体", required=true) @RequestBody WechatUserEntity wechatUser){
        ValidatorUtils.validateEntity(wechatUser, UpdateGroup.class);

		wechatUserService.updateById(wechatUser);

        return Result.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/delete")
    @RequiresPermissions("numcount:wechatuser:delete")
    public Result delete(@ApiParam(value = "id数组", required=true) @RequestBody Long[] ids){
		wechatUserService.removeByIds(Arrays.asList(ids));

        return Result.ok();
    }

}
